/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import javax.sip.address.Address;
import javax.sip.header.RecordRouteHeader;

/**
 * The Record-Route header field is inserted by proxies in a request to force
 * future requests in the dialog to be routed through the proxy. The
 * SipProvider (as opposed to the application) should attach Record-Route
 * headers to messages explicitly when forwarding them if necessary.
 * <p/>
 * The RecordRouteHeader is added to a Request by any proxy that insists on being
 * in the path of subsequent Requests for the same call leg. It contains
 * a globally reachable RequestURI that identifies the proxy server. Each proxy
 * server adds its Address URI to the beginning of the list.
 * <p/>
 * The calling user agent client copies the RecordRouteHeaders into
 * RouteHeaders of subsequent Requests within the same call leg, reversing the
 * order, so that the first entry is closest to the user agent client. If the
 * Response contained a ContactHeader field, the calling user agent adds its
 * content as the last RouteHeader. Unless this would cause a loop, a client
 * must send subsequent Requests for this call leg to the  Address URI in the
 * first RouteHeader and remove that entry.
 * <p/>
 * Some proxies, such as those controlling firewalls or in an automatic call
 * distribution (ACD) system, need to maintain call state and thus need to
 * receive any BYE and ACK Requests for the call.
 * <p/>
 * For Example:<br>
 * <code>Record-Route: sip:server10.jcp.org;lr,
 * sip:bigbox3.duke.jcp.org;lr</code>
 *
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 * @see javax.sip.header.RouteHeader
 * @see javax.sip.header.HeaderAddress
 * @see javax.sip.header.Parameters
 */
public class RecordRouteHeaderImpl extends ParametrizedHeaderBase implements RecordRouteHeader {
    private final static RecordRouteHeaderParser parser = new RecordRouteHeaderParser();
    private Address address;

    public RecordRouteHeaderImpl() {
        super(RecordRouteHeader.NAME);
    }

    RecordRouteHeaderImpl(byte[] data, int start, int end) {
        super(RecordRouteHeader.NAME, data, start, end);
    }

    public Object clone() {
        final RecordRouteHeaderImpl header = new RecordRouteHeaderImpl();
        header.cloneBase(this);
        if (parsed) {
            header.address = this.address;
        }
        return header;
    }

    protected HeaderParser getParser() {
        return parser;
    }

    protected String getValueAsString() {
        return address.toString();
    }

    /**
     * Sets the Address parameter of this Address.
     *
     * @param address the Address object that represents the new
     *                address of this Address.
     */
    public void setAddress(Address address) {
        parse();
        this.address = address;
        invalidateHeaderData();
    }

    /**
     * Gets the address parameter of this Address.
     *
     * @return the Address of this Address
     */
    public Address getAddress() {
        parse();
        return this.address;
    }
}
/*
 * $Log$
 */